#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct time
{
    int start;
    int over;
} a[210];
int cmp(time c,time b)
{
    return c.start<b.start;
}
int vis[210];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(vis,0,sizeof(vis));
        int n;
        scanf("%d",&n);
        for(int i=0; i<n; i++)
            scanf("%d%d",&a[i].start,&a[i].over);
        for(int i=0;i<n;i++)
        {
            if(a[i].start>a[i].over)
            {
                int y=a[i].start;
                a[i].start=a[i].over;
                a[i].over=y;
            }
            if(a[i].start%2==1)
            a[i].start=a[i].start/2+1;
            else a[i].start/=2;
            if(a[i].over%2==1)
                a[i].over=a[i].over/2+1;
            else
            a[i].over/=2;
        }
        sort(a,a+n,cmp);
        int step=0;
        int temp;
        for(int i=0; i<n; i++)
        {

            temp=a[i].over;
            if(vis[i]==0)
            {
                step++;
                for(int j=0; j<n; j++)
                {
                    if(a[j].start>temp&&vis[j]==0)
                    {
                        temp=a[j].over;
                        vis[j]=1;
                    }
                }
            }
        }
        printf("%d\n",step*10);
    }
}
